package com.itheima.sort;

public class A02_SelectionSort {
    public static void main(String[] args) {
        int[] arr = {2, 1, 5, 3, 4};
        //外循环代表第几轮，其中i表示拿着i索引上的元素和i后面的元素进行比较

        for (int i = 0; i < arr.length - 1; i++) {
            //内循环代表要比较的次数，拿着i和i后面元素进行比较
            for (int j = i+1; j < arr.length; j++) {
                if(arr[i]>arr[j]){
                    int temp=0;
                    temp=arr[j];
                    arr[j]=arr[i];
                    arr[i]=temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
